﻿Public Class FormSettings

    Private Shared m_Instance As FormSettings

    Private Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Public Shared Function ShowSettings() As System.Windows.Forms.DialogResult
        If m_Instance Is Nothing Then
            m_Instance = New FormSettings
        End If
        If Not m_Instance.Focused Then
            Return m_Instance.ShowDialog()
        End If
    End Function

    Private Sub FormSettings_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.ux_TextBoxGamerTag.Text = My.Settings.GamerTag
        Me.ux_TextBoxTwitterEmail.Text = My.Settings.TwitterEmail
        Me.ux_TextBoxTwitterPassword.Text = My.Settings.TwitterPassword
        Me.ux_TextBoxux_TextBoxTwitterUsername.Text = My.Settings.TwitterUsername
        Me.ux_NumericUpDownMinutesBetweenChecks.Value = My.Settings.MinutesBetweenChecks
        Me.ux_CheckBoxEnabled.Checked = My.Settings.Enabled
    End Sub


    Private Sub ux_ButtonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ux_ButtonOK.Click
        My.Settings.GamerTag = Me.ux_TextBoxGamerTag.Text
        My.Settings.TwitterEmail = Me.ux_TextBoxTwitterEmail.Text
        My.Settings.TwitterPassword = Me.ux_TextBoxTwitterPassword.Text
        My.Settings.TwitterUsername = Me.ux_TextBoxux_TextBoxTwitterUsername.Text
        My.Settings.MinutesBetweenChecks = Me.ux_NumericUpDownMinutesBetweenChecks.Value
        My.Settings.Enabled = Me.ux_CheckBoxEnabled.Checked
        My.Settings.Save()
        Me.Close()
    End Sub

    Public Shared Function CheckSettings() As Boolean
        Dim r As Boolean = True
        If My.Settings.GamerTag = "" Then
            Debug.Write("GamerTag: False")
            r = False
        End If
        If My.Settings.TwitterEmail = "" Then
            Debug.Write("TwitterEmail: False")
            r = False
        End If
        If My.Settings.TwitterPassword = "" Then
            Debug.Write("TwitterPassword: False")
            r = False
        End If
        If My.Settings.TwitterUsername = "" Then
            Debug.Write("TwitterUsername: False")
            r = False
        End If
        If My.Settings.MinutesBetweenChecks < 5 Then
            Debug.Write("MinutesBetweenChecks: False")
            r = False
        End If
        Return r
    End Function

    Private Sub ux_ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ux_ButtonCancel.Click
        Me.Close()
    End Sub

End Class